package edu.zut.cs.software.perfect.grade.service.impl;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import edu.zut.cs.software.perfect.base.service.impl.GenericManagerImpl;
import edu.zut.cs.software.perfect.grade.dao.CourseGradeDao;
import edu.zut.cs.software.perfect.grade.dao.StudentGradeDao;
import edu.zut.cs.software.perfect.grade.domain.StudentGrade;
import edu.zut.cs.software.perfect.grade.service.StudentGradeManager;
/**
 * @ClassName couseGradeManagerImpl
 * @Description TODO
 * @Author zhangwenkai
 * @Date 2020年4月5日 下午5:41:38
 * @Version 1.0
 */
@Service("couseGradeManager")
@Transactional
public class StudentGradeManagerImpl extends GenericManagerImpl<Long, StudentGrade> implements StudentGradeManager {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = LogManager.getLogger(StudentGradeManagerImpl.class.getName());
	
	@Override
	public List<StudentGrade> findAll() {
		return (List<StudentGrade>) this.dao.findAll();
	}

	 StudentGradeDao studentGradeDao;
	 
	 @Autowired
	public void setStudentGradeDao(StudentGradeDao studentGradeDao) {
		this.studentGradeDao = studentGradeDao;
		this.dao = studentGradeDao;
	}

	@Override
	public Optional<StudentGrade> findByCourseId(Long courseId) {
		Optional<StudentGrade> result = this.dao.findById(courseId);
		return result;
	}

	@Override
	public Boolean deleteById(Long courseId) {
		Optional<StudentGrade> studentGrade = this.dao.findById(courseId);
		if(studentGrade.equals(Optional.empty())) {
			return false;
		}else {
			this.dao.delete(studentGrade.get());
			return true;
		}
	}


	

	
}